package main

import (
	"os"
	"fmt"
	"github.com/Comdex/imgo"
	"strings"
	"log"
	"math"
)

func main() {
	args := os.Args
	arglen := len(args)

	if arglen < 2 {
		fmt.Println("please input img file")
		return
	}

	filePath := args[1]
	/*keepColor := ""
	if arglen > 2 {
		keepColor = args[2]
	}*/

	img := imgo.MustRead(filePath)
	for x := range img {
		for y := range img[x] {
			alpha := uint8(math.Min(255,float64(int(img[x][y][0]) + int(img[x][y][1]) + int(img[x][y][2]))))
			/*if len(keepColor) == 0 {*/
				img[x][y][0] = 255
				img[x][y][1] = 255
				img[x][y][2] = 255
			/*}*/
			img[x][y][3] = alpha
		}
	}

	tmp := strings.Split(filePath, ".")
	str := strings.Join(tmp[:len(tmp)-1], ".")
	err := imgo.SaveAsPNG(fmt.Sprintf("%s%d.%s", str, 1, tmp[len(tmp)-1]), img)
	if err != nil {
		log.Fatal(err)
	}
}
